package com.zhaopin.mianshi;

/**
 * @author yin.peide
 * @date 2021-05-14 14:18
 * 求 二叉树的深度
 * ————————————————
 *         版权声明：本文为CSDN博主「喜欢ctrl的cxk」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
 *         原文链接：https://blog.csdn.net/weixin_42449444/article/details/86248248
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }

    public static void main(String[] args) {
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode9 = new TreeNode(9);
        TreeNode treeNode20 = new TreeNode(20);
        TreeNode treeNode15 = new TreeNode(15);
        TreeNode treeNode7 = new TreeNode(7);

        treeNode3.left = treeNode9;
        treeNode3.right = treeNode20;
        treeNode20.left = treeNode15;
        treeNode20.right = treeNode7;

        Solution solution = new Solution();
        System.out.println(solution.maxDepth(treeNode3));
    }
}


class Solution {
    public int maxDepth(TreeNode root) {
        return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }
}

